<?php
class Formulario {

	static public function dibujar_select(array $opciones, array $atributos = array(), $selected = false) {
		
		// Preparo los atributos
		$atribs = array();
		foreach ($atributos as $atrib => $valor) {
			$atrib		= htmlentities($atrib);
			$valor		= htmlentities($valor);
			$atribs[]	= "$atrib=\"$valor\"";
		}
		$atribsTxt = implode(' ', $atribs);

		// Preparo las opciones
		$ops = array();
		foreach ($opciones as $valor => $texto) {
			$selec = $selected==$valor ? ' selected="selected"' : '';
			$valor = htmlentities($valor);
			$texto = htmlentities($texto);
			$ops[] = "<option value=\"$valor\"$selec>$texto</option>";
		}
		$opsTxt = implode("\n\t", $ops);
		
		// Dibujo
		echo "\n<select $atribsTxt>";
		echo "\n\t$opsTxt";
		echo "\n</select>\n";
		
	}

}